using System;
using System.Collections;
using System.Collections.Generic;
using Mgrs;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public class Dialog : MonoBehaviour,IPointerClickHandler
{
    public GameObject _DialogBox;
    public Text dialogBoxText;
    
    private  int StartID, EndID;

  
   // public Dictionary<int, string[]> Dialogs;
    private int dialogueDbId=0;
    
    private string[] str;
    private DialogType getDialogType;
    
  
    
    // Update is called once per frame
    public void OpenDialogDescri(string talkSelect)
    {
        dialogBoxText.text = talkSelect;
    }

    public void Awake()
    {
    }

   

    //点击事件
    public void OnPointerClick(PointerEventData eventData)
    {
        dialogueDbId++;
       
    
       if (dialogueDbId == EndID)
       {
           Dialogue();
       }
       else
       {
           OpenDialogDescri(str[dialogueDbId]); 
       }
       
       
       
        Debug.Log("进入下一个事件");
    }
    
    
    public void DialogueEvent(DialogType dialogType)
    { 
         
        getDialogType=dialogType;
        str=ConversationDb.dialogs[(int)dialogType];
       
        dialogueDbId = 0;
        StartID = 0;
        EndID = str.Length;
        
        OpenDialogDescri(str[dialogueDbId]);
       
    }


    void Dialogue()
    {
        if (dialogueDbId==EndID)
        {
            
            switch (getDialogType)
            {
                case DialogType.NextEvent:
                    GameObject.Find("Panel_EventCardControl(Clone)").GetComponent<EventCardcontrol>().ShowEventCard();
                    Destroy(_DialogBox.gameObject);
                    break;
                case DialogType.PatientEvent:
                    SceneManager.LoadScene("TreatPatientScene");
                    Destroy(_DialogBox.gameObject);
                    break;
                case DialogType.Merchant:
                    GameObject.Find("Panel_EventCardControl(Clone)").GetComponent<EventCardcontrol>().ShowShop();
                    Destroy(_DialogBox.gameObject);
                    break;
            }
        }
    }
    
    
}
